package com.example.demo.controller;

import com.example.demo.exception.MyUncheckedException;
import com.example.demo.pojo.Result;
import com.example.demo.pojo.dto.QuestionDTO;
import com.example.demo.pojo.entity.QuestionBank;
import com.example.demo.pojo.entity.QuestionFile;
import com.example.demo.pojo.query.BankQuery;
import com.example.demo.pojo.query.PageQuery;
import com.example.demo.pojo.vo.QuestionVO;
import com.example.demo.service.imply.IBankServiceImply;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

/**
 * @author fjh
 */
@RestController
@RequestMapping("/bank")
@Slf4j
@Api(tags = "题目相关接口")
@RequiredArgsConstructor
@CrossOrigin(origins = {"http://localhost:8080"}, allowCredentials = "true")
public class BankController {
    private  final IBankServiceImply bankService;
    @ApiOperation("过滤题目")
    @PostMapping("/filter")
    public Result filter(@RequestBody BankQuery bankQuery){
        List<QuestionVO>result=bankService.queryQuestion(bankQuery);
        if(result==null){
            return Result.error("过滤失败");
        }
        System.out.println(result.size());
        return Result.success(result);
    }
    @ApiOperation("分页查询")
    @PostMapping("/page")
    public Result page(PageQuery pageQuery){
        List<QuestionVO>result=bankService.queryPage(pageQuery.getPageNo(),pageQuery.getPageSize());
        return Result.success(result);
    }
    @ApiOperation("根据id从store进行查询")
    @PostMapping("/searchById")
    public Result searchByIdFromStore(int bankId){
        QuestionVO result=bankService.searchByIdFromStore(bankId);
        return Result.success(result);
    }
}
